<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../ht-css/Project.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css"/>
    <link rel="stylesheet" href="../../ht-css/combo.select.css">
    <title>场景标签</title>
</head>
<body>
<article class="">
    <form class="ml-20 mr-20" id="form-member-add" method="post">
        <div>
            <div class="pd-5 bg-1 bk-gray pb-10">
                <div class="lh-30 pd-10">
                    <table class="table-hover ml-10 mb-10 table">
                        <thead class="text-l">
                        <tr>
                            <td>
                                <div class="formControls">
                                    <input type="text" autocomplete="off" class="input-text radius" name="class1" placeholder="请选择一级场景标签" oninput="goods_listLable(1)" id="class1">
                                    <ul class="relation radius guanlian" id="scene1">
                                    </ul>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="formControls">
                                    <input type="text" autocomplete="off" class="input-text radius" name="class2" placeholder="请选择二级场景标签" id="class2">
                                    <ul class="relation radius guanlian" id="scene2">
                                    </ul>
                                </div>
                            </td>
                        </tr>
                        </thead>
                    </table>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                            <button type="button" onclick="saveScene()" class="btn btn-primary radius subSure">&nbsp;&nbsp;确认&nbsp;&nbsp;</button>
                            <button onclick="removeIframe()" class="btn btn-default radius ml-10" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script type="text/javascript" src="../../ht-js/frame/doT.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.combo.select.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/Project.js?rev=@@hash"></script>
<script>
    /*取消*/
    function removeIframe() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    var lableId1;
    var lableId2;
    function saveScene() {
        if($("#class1").val() == "" || $("#class2").val() == "" || lableId1 == "" || lableId2 == ""){
            layer.msg("场景参数不能为空", {icon: 5, time: 1000});
        }else {
            if (sessionStorage.getItem("scene_lable")) {
                var scene_lable = JSON.parse(sessionStorage.getItem("scene_lable"));
                var lableNameArr = {};
                lableNameArr.class1 = $("#class1").val();
                lableNameArr.class2 = $("#class2").val();
                lableNameArr.lableId1 = lableId1;
                lableNameArr.lableId2 = lableId2;
                scene_lable.push(lableNameArr)
                console.log(lableNameArr)
                sessionStorage.setItem("scene_lable", JSON.stringify(scene_lable));
            } else {
                var scene_lable = [];
                var lableNameArr = {
                    class1: $("#class1").val(),
                    class2: $("#class2").val(),
                    lableId1: lableId1,
                    lableId2: lableId2
                };
                scene_lable.push(lableNameArr)
                sessionStorage.setItem("scene_lable", JSON.stringify(scene_lable));
            }
            /*var i = parent.location.reload();
            parent.layer.close(i);*/
            window.parent.SceneTags();
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    }

    /*场景标签管理------------------------------start---------------------------------------------*/
    function goods_listLable(lable_level) {
        var user_data = {
            lable_level: lable_level,
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if (data.errorCode == "0") {
                if (data.data.length == 0) {
                    classStr = "<li>无数据</li>"
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='nextClassLable(\"" + data.data[i].lable_id + "\",\"" + data.data[i].lable_name + "\",1)'>" + data.data[i].lable_name + "</li>"
                    }
                }
                $("#scene" + data.data[0].lable_level + "").html(classStr);
            }
        }
        web.doAjax(root.goodsInter.goods_listLable, 'get', user_data, succCallBack);
    }

    //获取光标
    $("#class1").focus(function () {
        $("#scene1").show();
        goods_listLable(1);
        $("#scene2").hide();
    });
    $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
        if ($(e.target).closest("#scene1").length == 0 && $(e.target).closest("#class1").length == 0) {
//点击id为menu之外且id不是不是open，则触发
            $("#scene1").hide()
        }
    });
    //获取光标
    $("#class2").focus(function () {
        $("#scene2").show();
    });
    $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
        if ($(e.target).closest("#scene2").length == 0 && $(e.target).closest("#class2").length == 0) {
//点击id为menu之外且id不是不是open，则触发
            $("#scene2").hide()
        }
    });

    function getNext_inputL(level, lable_id) {
        $("#class" + level + "")[0].oninput = function () {
            // nextClassLable(level, level);
        }
//获取光标
        $("#class" + level + "").focus(function () {
            $("#scene" + level + "").show();
            // nextClassLable(level, level, lable_id);
        });
        $(document).bind("click", function (e) {
//id为menu的是菜单，id为open的是打开菜单的按钮
            if ($(e.target).closest("#scene" + level + "").length == 0 && $(e.target).closest("#class" + level + "").length == 0) {
//点击id为menu之外且id不是不是open，则触发
                $("#scene" + level + "").hide()
            }
        });
    }

    function nextClassLable(lable_id, lable_name, level) {
        if (level == 1) {
            $("#scene2").html("");
            $("#class1").val(lable_name);
            $("#scene1").hide();
            $("#scene2").show();
            $("#class2").val("");
            lableId1 = lable_id;
            lableId2 = "";
        } else if (level == 2) {
            $("#class2").val(lable_name);
            $("#scene2").hide();
            lableId2 = lable_id;
        }

        var user_data = {
            lable_id: lable_id
        }
        var succCallBack = function (data, status, response) {
            if (data.errorCode == "0") {
                console.log(data.data.length)
                if (data.data.length == []) {
                    console.log(7878)
                    classStr = "<li>无数据</li>"
                    if (level == 1){
                        $("#scene2").html(classStr);
                        $("#scene2").show();
                    }
                } else {
                    var classStr = "";
                    for (var i = 0; i < data.data.length; i++) {
                        classStr += "<li onclick='nextClassLable(" + data.data[i].lable_id + ",\"" + data.data[i].lable_name + "\",2)'>" + data.data[i].lable_name + "</li>"
                    }
                    $("#scene2").html(classStr);
                    if (level == 1){
                        $("#scene2").show();
                    }
                }
            }
        }
        $("#scene1").hide()
        // getNext_inputL(level, lable_id);
        web.doAjax(root.goodsInter.goods_listSubLable, 'post', user_data, succCallBack);
    }
</script>
</body>
</html>